<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/assets/img/favicon.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicon.ico">
  <link rel="mask-icon" href="/assets/img/favicon.ico" color="#222">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-bounce.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lzqblog.top","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"always","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"default"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="SWUpdate is a popular embedded system update framework. I’m trying to bring up a OTA update system on stm32mp1, and this OTA system will base on SWUpdate. This post records steps need to be done to in">
<meta property="og:type" content="article">
<meta property="og:title" content="SWUpdate bring up (I): Install to Yocto Linux and create single copy image">
<meta property="og:url" content="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/index.html">
<meta property="og:site_name" content="Coding Spirit">
<meta property="og:description" content="SWUpdate is a popular embedded system update framework. I’m trying to bring up a OTA update system on stm32mp1, and this OTA system will base on SWUpdate. This post records steps need to be done to in">
<meta property="og:image" content="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/webserver.png">
<meta property="og:image" content="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/uploading.png">
<meta property="og:image" content="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/reboot.png">
<meta property="article:published_time" content="2020-04-05T08:15:54.000Z">
<meta property="article:modified_time" content="2020-04-06T05:08:09.303Z">
<meta property="article:author" content="Coding Spirit">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="Yocto">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/webserver.png">

<link rel="canonical" href="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-Hans'
  };
</script>

  <title>SWUpdate bring up (I): Install to Yocto Linux and create single copy image | Coding Spirit</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-154617667-1"></script>
    <script>
      if (CONFIG.hostname === location.hostname) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-154617667-1');
      }
    </script>






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Coding Spirit</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">一位程序员，比较帅的那种</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="Searching..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/codingspirit" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/assets/img/coding_spirit.jpg">
      <meta itemprop="name" content="Coding Spirit">
      <meta itemprop="description" content="毕业于OUC，现就职于Amazon">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Coding Spirit">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          SWUpdate bring up (I): Install to Yocto Linux and create single copy image
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2020-04-05 16:15:54" itemprop="dateCreated datePublished" datetime="2020-04-05T16:15:54+08:00">2020-04-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2020-04-06 13:08:09" itemprop="dateModified" datetime="2020-04-06T13:08:09+08:00">2020-04-06</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%B3%BB%E7%BB%9F%E6%9E%84%E5%BB%BA/" itemprop="url" rel="index"><span itemprop="name">系统构建</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="Views" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">Views: </span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="Symbols count in article">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">Symbols count in article: </span>
              <span>5.5k</span>
            </span>
            <span class="post-meta-item" title="Reading time">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">Reading time &asymp;</span>
              <span>5 mins.</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><a href="https://github.com/sbabic/meta-swupdate-boards" target="_blank" rel="noopener">SWUpdate</a> is a popular embedded system update framework. I’m trying to bring up a OTA update system on stm32mp1, and this OTA system will base on SWUpdate. This post records steps need to be done to install SWUpdate system into Yocto Linux, and create a single copy image to test it.</p>
<a id="more"></a>

<h2 id="meta-swupdate"><a href="#meta-swupdate" class="headerlink" title="meta-swupdate"></a>meta-swupdate</h2><p><a href="https://github.com/sbabic/meta-swupdate-boards" target="_blank" rel="noopener">SWUpdate</a> was provided to help generate SWUpdate supported images. Clone it to the layers path and add it into <span style="color:red"><strong>conf/bblayers.conf</strong></span>.</p>
<blockquote>
<p>Notes:<br>This layer depends on several recipes in meta-openembedded. i.e. <strong>librsync</strong> and <strong>libubootenv</strong>. For STM32MP distribution, the default meta-openembedded version is too old and those recipes are not included yet. To continue, add those recipes manually or reset meta-openembedded to a newer version.</p>
</blockquote>
<h2 id="Boards-related-configs"><a href="#Boards-related-configs" class="headerlink" title="Boards related configs"></a>Boards related configs</h2><h3 id="SWUpdate-defconfig"><a href="#SWUpdate-defconfig" class="headerlink" title="SWUpdate defconfig"></a>SWUpdate defconfig</h3><p><span style="color:red"><strong>defconfig</strong></span> was required by swupdate.inc. Use menuconfig to create one for your boards as defconfig.</p>
<blockquote>
<p>Notes:<br>If <span style="color:blue">CONFIG_WEBSERVER</span> and <span style="color:blue">CONFIG_MONGOOSE</span> was enabled in menuconfig, target boards will run a mongoose webserver so user can access it through <span style="color:red">&lt;target_ip&gt;:8080</span> by default</p>
</blockquote>
<h3 id="SWUpdate-swupdate-cfg"><a href="#SWUpdate-swupdate-cfg" class="headerlink" title="SWUpdate swupdate.cfg"></a>SWUpdate swupdate.cfg</h3><p><span style="color:red"><strong>swupdate.cfg</strong></span> will be copied to target as swupdate runtime configurations. In <strong>swupdate.cfg</strong> we can set <code>board idendity</code>,<code>public-key</code>,<code>suricatta</code>, <code>webserver</code> and even more:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">globals :</span><br><span class="line">&#123;</span><br><span class="line">	verbose &#x3D; true;</span><br><span class="line">	loglevel &#x3D; 5;</span><br><span class="line">	syslog &#x3D; true;</span><br><span class="line">	no-downgrading &#x3D; &quot;1.0.0&quot;;</span><br><span class="line">	postupdatecmd &#x3D; &quot;reboot&quot;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">download :</span><br><span class="line">&#123;</span><br><span class="line">	retries &#x3D; 3;</span><br><span class="line">	timeout &#x3D; 1800;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">identify : (</span><br><span class="line">	&#123; name &#x3D; &quot;stm32mp157a-cp&quot;; value &#x3D; &quot;1.0&quot;; &#125;</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line">webserver :</span><br><span class="line">&#123;</span><br><span class="line">	document_root &#x3D; &quot;&#x2F;www&quot;;</span><br><span class="line">	userid		&#x3D; 0;</span><br><span class="line">	groupid		&#x3D; 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="09-swupdate-args"><a href="#09-swupdate-args" class="headerlink" title="09-swupdate-args"></a>09-swupdate-args</h3><p>This file defines extra parameters for swupdate daemon.</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">HARDWARE=<span class="string">"stm32mp157a-cp:1.0"</span></span><br><span class="line">CFGFILE=<span class="string">"/etc/swupdate.cfg"</span></span><br><span class="line">SWUPDATE_ARGS=<span class="string">"-H <span class="variable">$&#123;HARDWARE&#125;</span> -f <span class="variable">$&#123;CFGFILE&#125;</span>"</span></span><br></pre></td></tr></table></figure>

<p>Here we specific hardware information thus SWUpdate daemon will check swu image hardware compatibility before updating. If user trying to use swu image without specific hardware compatibility, SWUpdate will refuse to update.</p>
<h3 id="Use-bbappend-to-add-board-related-configs-in"><a href="#Use-bbappend-to-add-board-related-configs-in" class="headerlink" title="Use bbappend to add board related configs in"></a>Use <strong>bbappend</strong> to add board related configs in</h3><p>In boards specific layer, create file <code>swupdate_%.bbappend</code>:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">FILESEXTRAPATHS_append :&#x3D; &quot;$&#123;THISDIR&#125;&#x2F;$&#123;PN&#125;:&quot;</span><br><span class="line"></span><br><span class="line">PACKAGECONFIG_CONFARGS &#x3D; &quot;&quot;</span><br><span class="line"></span><br><span class="line">SRC_URI +&#x3D; &quot; \</span><br><span class="line">    file:&#x2F;&#x2F;swupdate.cfg \</span><br><span class="line">    file:&#x2F;&#x2F;09-swupdate-args \</span><br><span class="line">    &quot;</span><br><span class="line"></span><br><span class="line">do_install_append() &#123;</span><br><span class="line">    install -m 0644 $&#123;WORKDIR&#125;&#x2F;09-swupdate-args $&#123;D&#125;$&#123;libdir&#125;&#x2F;swupdate&#x2F;conf.d&#x2F;</span><br><span class="line"></span><br><span class="line">    install -d $&#123;D&#125;$&#123;sysconfdir&#125;</span><br><span class="line">    install -m 0644 $&#123;WORKDIR&#125;&#x2F;swupdate.cfg $&#123;D&#125;$&#123;sysconfdir&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Now we have structure like this in boards specific layer:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">└── swupdate</span><br><span class="line">    ├── swupdate</span><br><span class="line">    │   ├── 09-swupdate-args</span><br><span class="line">    │   ├── defconfig</span><br><span class="line">    │   └── swupdate.cfg</span><br><span class="line">    └── swupdate_%.bbappend</span><br></pre></td></tr></table></figure>

<h2 id="Install-to-image"><a href="#Install-to-image" class="headerlink" title="Install to image"></a>Install to image</h2><p>Then we need to add <code>swupdate</code>, <code>swupdate-www</code> and <code>libubootenv-bin</code> into image.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">IMAGE_INSTALL_append &#x3D; &quot; swupdate swupdate-www libubootenv-bin&quot;</span><br></pre></td></tr></table></figure>

<p>Flash the built image to target, make sure PC and target board are in same LAN, then we can access <span style="color:red">&lt;target_ip&gt;:8080</span> :</p>
<p><img src="/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/webserver.png" alt></p>
<h2 id="Create-a-single-copy-update-image-for-test"><a href="#Create-a-single-copy-update-image-for-test" class="headerlink" title="Create a single copy update image for test"></a>Create a single copy update image for test</h2><p>Now it’s time to create a swu image to test SWUpdate system.</p>
<h3 id="sw-description"><a href="#sw-description" class="headerlink" title="sw-description"></a>sw-description</h3><p><span style="color:red"><strong>sw-description</strong></span> defines the compatibility and usage of <code>swu</code> images. Here we defined a single copy update image, which is compatible with boards <code>stm32mp157a-cp</code> and will update target rootfs:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">software &#x3D;</span><br><span class="line">&#123;</span><br><span class="line">	version &#x3D; &quot;1.0.0&quot;;</span><br><span class="line"></span><br><span class="line">	stm32mp157a-cp &#x3D; &#123;</span><br><span class="line">		hardware-compatibility: [ &quot;1.0&quot; ];</span><br><span class="line">		images: (</span><br><span class="line">			&#123;</span><br><span class="line">				filename &#x3D; &quot;cp-image-core-openstlinux-eglfs-stm32mp1-cp.ext4.gz&quot;;</span><br><span class="line">				type &#x3D; &quot;raw&quot;;</span><br><span class="line">				sha256 &#x3D; &quot;@cp-image-core-openstlinux-eglfs-stm32mp1-cp.ext4.gz&quot;;</span><br><span class="line">				installed-directly &#x3D; true;</span><br><span class="line">				compressed &#x3D; true;</span><br><span class="line">				device &#x3D; &quot;&#x2F;dev&#x2F;mmcblk0p6&quot;;</span><br><span class="line">			&#125;</span><br><span class="line">		);</span><br><span class="line">	&#125;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Recipe-for-update-image"><a href="#Recipe-for-update-image" class="headerlink" title="Recipe for update image"></a>Recipe for update image</h3><p>To generate a <code>swu</code> file from bitbake, we need to create a recipe for update image. In my scenario it was named as <strong>cp-image-update.bb</strong> :</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">DESCRIPTION &#x3D; &quot;SWUpdate compound image&quot;</span><br><span class="line"></span><br><span class="line">LICENSE &#x3D; &quot;MIT&quot;</span><br><span class="line">LIC_FILES_CHKSUM &#x3D; &quot;file:&#x2F;&#x2F;$&#123;COMMON_LICENSE_DIR&#125;&#x2F;MIT;md5&#x3D;0835ade698e0bcf8506ecda2f7b4f302&quot;</span><br><span class="line"></span><br><span class="line">inherit swupdate</span><br><span class="line"></span><br><span class="line">SRC_URI &#x3D; &quot; \</span><br><span class="line">    file:&#x2F;&#x2F;sw-description \</span><br><span class="line">&quot;</span><br><span class="line"></span><br><span class="line"># images to build before building swupdate image</span><br><span class="line">IMAGE_DEPENDS &#x3D; &quot;cp-image-core&quot;</span><br><span class="line"></span><br><span class="line"># images and files that will be included in the .swu image</span><br><span class="line">SWUPDATE_IMAGES &#x3D; &quot;cp-image-core-openstlinux-eglfs-stm32mp1-cp&quot;</span><br><span class="line"></span><br><span class="line">SWUPDATE_IMAGES_FSTYPES[cp-image-core-openstlinux-eglfs-stm32mp1-cp] &#x3D; &quot;.ext4.gz&quot;</span><br></pre></td></tr></table></figure>

<p>Now we have structure like this in boards specific layer:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">.</span><br><span class="line">├── images</span><br><span class="line">│   ├── cp-image-update</span><br><span class="line">│   │   └── sw-description</span><br><span class="line">│   └── cp-image-update.bb</span><br></pre></td></tr></table></figure>

<p>To generate <code>swu</code> image, call <code>bitbake cp-image-update</code>.</p>
<h3 id="Generate-update-image-without-image-recipe"><a href="#Generate-update-image-without-image-recipe" class="headerlink" title="Generate update image without image recipe"></a>Generate update image without image recipe</h3><p>Sometimes we want to generate a <code>swu</code> image for test purpose, in this scenario we can skip <code>bitbake</code> and use a simple shell script to generate <code>swu</code> image quickly:</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line"></span><br><span class="line">CONTAINER_VER=<span class="string">"1.0"</span></span><br><span class="line">PRODUCT_NAME=<span class="string">"stm32mp157-cp"</span></span><br><span class="line">FILES=<span class="string">"sw-description cp-image-core-openstlinux-eglfs-stm32mp1-cp.ext4.gz"</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="variable">$FILES</span>;<span class="keyword">do</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="variable">$i</span>;<span class="keyword">done</span> | cpio -ov -H crc &gt;  <span class="variable">$&#123;PRODUCT_NAME&#125;</span>_<span class="variable">$&#123;CONTAINER_VER&#125;</span>.swu</span><br></pre></td></tr></table></figure>

<h3 id="Quick-check-structure-of-generated-swu-image"><a href="#Quick-check-structure-of-generated-swu-image" class="headerlink" title="Quick check structure of generated swu image"></a>Quick check structure of generated swu image</h3><p>Since swu image was cpio based, we can use <code>cat</code> to check structure of it:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cat cp-image-update-openstlinux-eglfs-stm32mp1-cp.swu | cpio -it</span><br><span class="line">sw-description</span><br><span class="line">cp-image-core-openstlinux-eglfs-stm32mp1-cp.ext4.gz</span><br><span class="line">88360 blocks</span><br></pre></td></tr></table></figure>

<h2 id="Test-with-generated-swu-image-on-target"><a href="#Test-with-generated-swu-image-on-target" class="headerlink" title="Test with generated swu image on target"></a>Test with generated swu image on target</h2><h3 id="Use-web-interface"><a href="#Use-web-interface" class="headerlink" title="Use web interface"></a>Use web interface</h3><p>We can trigger update easily by uploading <code>swu</code> image through webserver:</p>
<p><img src="/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/uploading.png" alt></p>
<p>We defined     <code>postupdatecmd = &quot;reboot&quot;;</code> in <span style="color:red"><strong>swupdate.cfg</strong></span>, so system will automatically reboot:</p>
<p><img src="/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/reboot.png" alt></p>
<h3 id="Use-command-line-interface"><a href="#Use-command-line-interface" class="headerlink" title="Use command line interface"></a>Use command line interface</h3><p>We also can use command line to trigger update if we have an usb drive which contains <strong>swu</strong> image and has connected to target:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">swupdate -i &#x2F;media&#x2F;cp-image-update-openstlinux-eglfs-stm32mp1-cp.swu -H stm32mp157a-cp:1.0</span><br></pre></td></tr></table></figure>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>Post author:  </strong>Coding Spirit
  </li>
  <li class="post-copyright-link">
    <strong>Post link: </strong>
    <a href="https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/" title="SWUpdate bring up (I): Install to Yocto Linux and create single copy image">https://lzqblog.top/2020-04-05/SWUpdate-bring-up-I-Install-to-Yocto-Linux-and-create-single-copy-image/</a>
  </li>
  <li class="post-copyright-license">
    <strong>Copyright Notice:  </strong>All articles in this blog are licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> unless stating additionally.
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Linux/" rel="tag"><i class="fa fa-tag"></i> Linux</a>
              <a href="/tags/Yocto/" rel="tag"><i class="fa fa-tag"></i> Yocto</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020-03-08/nfsroot-boot-crash-after-systemd-networkd-starts/" rel="prev" title="nfsroot boot crash after systemd-networkd starts">
      <i class="fa fa-chevron-left"></i> nfsroot boot crash after systemd-networkd starts
    </a></div>
      <div class="post-nav-item">
    <a href="/2020-04-13/AWS-IoT-Getting-Started-MQTT-sample/" rel="next" title="AWS IoT Getting Started: MQTT sample">
      AWS IoT Getting Started: MQTT sample <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#meta-swupdate"><span class="nav-number">1.</span> <span class="nav-text">meta-swupdate</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Boards-related-configs"><span class="nav-number">2.</span> <span class="nav-text">Boards related configs</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#SWUpdate-defconfig"><span class="nav-number">2.1.</span> <span class="nav-text">SWUpdate defconfig</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SWUpdate-swupdate-cfg"><span class="nav-number">2.2.</span> <span class="nav-text">SWUpdate swupdate.cfg</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#09-swupdate-args"><span class="nav-number">2.3.</span> <span class="nav-text">09-swupdate-args</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Use-bbappend-to-add-board-related-configs-in"><span class="nav-number">2.4.</span> <span class="nav-text">Use bbappend to add board related configs in</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Install-to-image"><span class="nav-number">3.</span> <span class="nav-text">Install to image</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Create-a-single-copy-update-image-for-test"><span class="nav-number">4.</span> <span class="nav-text">Create a single copy update image for test</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#sw-description"><span class="nav-number">4.1.</span> <span class="nav-text">sw-description</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Recipe-for-update-image"><span class="nav-number">4.2.</span> <span class="nav-text">Recipe for update image</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Generate-update-image-without-image-recipe"><span class="nav-number">4.3.</span> <span class="nav-text">Generate update image without image recipe</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Quick-check-structure-of-generated-swu-image"><span class="nav-number">4.4.</span> <span class="nav-text">Quick check structure of generated swu image</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Test-with-generated-swu-image-on-target"><span class="nav-number">5.</span> <span class="nav-text">Test with generated swu image on target</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Use-web-interface"><span class="nav-number">5.1.</span> <span class="nav-text">Use web interface</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Use-command-line-interface"><span class="nav-number">5.2.</span> <span class="nav-text">Use command line interface</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Coding Spirit"
      src="/assets/img/coding_spirit.jpg">
  <p class="site-author-name" itemprop="name">Coding Spirit</p>
  <div class="site-description" itemprop="description">毕业于OUC，现就职于Amazon</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">113</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">39</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/codingspirit" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;codingspirit" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:596544399@qq.com" title="E-Mail → mailto:596544399@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

      
        
          <div id="musicPlayerPost">
            <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=400876433&auto=0&height=66"></iframe>
          </div>
        
      
      

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Powered by Coding Spirit. All rights reserved.</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="Symbols count total">220k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="Reading time total">3:20</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>













  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID    : '965ca656ae3d59a50b73',
      clientSecret: '94dbe9c760ce8b778c84481a7fe2f37f548d7375',
      repo        : 'blog-gitalk',
      owner       : 'codingspirit',
      admin       : ['codingspirit'],
      id          : '6f041cc78c9b81effa197edda27ce8cc',
        language: '',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

</body>
  
    <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas>
    <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script>
    <script type="text/javascript" src="/js/src/fireworks.js"></script>
  
</html>
